// import com.alibaba.druid.sql.ast.statement.SQLWithSubqueryClause.Entry;
// import com.alibaba.druid.sql.dialect.oracle.ast.OracleSQLObject;
// import com.alibaba.druid.sql.dialect.oracle.visitor.OracleASTVisitor;
// import com.alibaba.druid.sql.visitor.SQLASTVisitor;

#include "OracleWithSubqueryEntry.h"
#include "../../visitor/OracleASTVisitor.h"
#include "../../../../visitor/SQLASTVisitor.h"
#include "CycleClause.h"
#include "SearchClause.h"
#include "../../../../../utils/listTran.h"

CycleClause_ptr OracleWithSubqueryEntry::getCycleClause()
{
  return cycleClause;
}

void OracleWithSubqueryEntry::setCycleClause(CycleClause_ptr cycleClause)
{
  if (cycleClause != nullptr)
  {
    cycleClause->setParent(SharedObject(OracleWithSubqueryEntry));
  }
  this->cycleClause = cycleClause;
}

SearchClause_ptr OracleWithSubqueryEntry::getSearchClause()
{
  return searchClause;
}

void OracleWithSubqueryEntry::setSearchClause(SearchClause_ptr searchClause)
{
  if (searchClause != nullptr)
  {
    searchClause->setParent(SharedObject(OracleWithSubqueryEntry));
  }
  this->searchClause = searchClause;
}

// @Override
void OracleWithSubqueryEntry::accept0(OracleASTVisitor_ptr visitor)
{
  if (visitor->visit(SharedObject(OracleWithSubqueryEntry)))
  {
    SQLObject_list_ptr tmp1 = ListTran::tran_class<SQLName, SQLObject>(columns);
    acceptChild(visitor, tmp1);
    acceptChild(visitor, subQuery);
    acceptChild(visitor, searchClause);
    acceptChild(visitor, cycleClause);
  }
  visitor->endVisit(SharedObject(OracleWithSubqueryEntry));
}

// @Override
void OracleWithSubqueryEntry::accept0(SQLASTVisitor_ptr visitor)
{
  this->accept0(std::dynamic_pointer_cast<OracleASTVisitor>(visitor));
}

void OracleWithSubqueryEntry::cloneTo(OracleWithSubqueryEntry_ptr x)
{

  SQLWithSubqueryClause_Entry::cloneTo(x);

  if (searchClause != nullptr)
  {
    setSearchClause(std::dynamic_pointer_cast<SearchClause>(searchClause->clone()));
  }

  if (cycleClause != nullptr)
  {
    setCycleClause(std::dynamic_pointer_cast<CycleClause>(cycleClause->clone()));
  }
}

SQLObject_ptr OracleWithSubqueryEntry::clone()
{
  SQLObject_ptr clone_tmp = std::shared_ptr<OracleWithSubqueryEntry>(new OracleWithSubqueryEntry());
  std::shared_ptr<OracleWithSubqueryEntry> x = std::dynamic_pointer_cast<OracleWithSubqueryEntry>(clone_tmp);
  // OracleWithSubqueryEntry x = new OracleWithSubqueryEntry();
  cloneTo(x);
  return x;
}
